class Solution(object):
    def minIncrementForUnique(self, nums):
        t = 0
        n = max(nums)
        DP = [0] * (n + 1)
        for num in nums:
            DP[num] += 1
        for i in range(1, n):
            if DP[i] > 1:
                diff = DP[i] - 1
                t += diff
                DP[i + 1] += diff
        if DP[n] > 1:
            diff = DP[n] - 1
            t += (diff + 1) * diff // 2
        return t



data = Solution()
nums = [3, 2, 1, 2, 1, 7]
print(data.minIncrementForUnique(nums))
